#!/bin/sh

# Copyright (c) 2006-2012, Universities Space Research Association (USRA).
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#     * Redistributions of source code must retain the above copyright
#       notice, this list of conditions and the following disclaimer.
#     * Redistributions in binary form must reproduce the above copyright
#       notice, this list of conditions and the following disclaimer in the
#       documentation and/or other materials provided with the distribution.
#     * Neither the name of the Universities Space Research Association nor the
#       names of its contributors may be used to endorse or promote products
#       derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY USRA ``AS IS'' AND ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL USRA BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

# The purpose of this script is to collect information specific to your
# system and output it to a text file 'userinfo-(currentdate).txt'.
# If you experience problems during installation, execution, etc.,
# this system specific information should be forwarded to:
#
# plexil-support@sourceforge.net
#
# so the Plexil group can be better equiped to help resolve your issue.

if [ -z "$PLEXIL_HOME" ]
then
    echo Error: Please set environment variable PLEXIL_HOME
    echo to the full pathname of your 'plexil' or 'trunk' directory.
    echo Exiting.
    exit 2
fi
 
/bin/rm -f $PLEXIL_HOME/userinfo*

output=$PLEXIL_HOME/userinfo-$(date +%m-%d-%Y).txt

echo "Creating file containing info about your system here: $output"

echo "# This file was created by the env-info script located in PLEXIL_HOME/bin.
# If you have experienced a problem during installation, execution, etc., 
# please email this file to:
#
# plexil-support@sourceforge.net
#
# so the Plexil group can be better equipped to help resolve your issue." > $output

echo "" >> $output
echo `date`>> $output
echo "" >> $output

echo "ENVIRONMENT VARIABLES" >> $output 
echo "--------------------------------" >> $output

# collect PLEXIL_HOME definition
echo "PLEXIL_HOME =" $PLEXIL_HOME >> $output | tee >> $output 

# collect LD_LIBRARY_PATH or DYLD_LIBRARY_PATH definition
echo "LD_LIBRARY_PATH =" $LD_LIBRARY_PATH >> $output | tee >> $output 
echo "DYLD_LIBRARY_PATH =" $DYLD_LIBRARY_PATH >> $output | tee >> $output 

# collect WHICH JAVA definition
JAVA=`which java`
echo "WHICH JAVA =" $JAVA >> $output | tee >> $output 

# collect PATH definition
echo "PATH =" $PATH >> $output | tee >> $output 
echo "" >> $output

# if used SVN, collect revision info
echo "SVN INFO" >> $output
echo "--------------------------------" >> $output
svn info $PLEXIL_HOME >> $output | tee >> $output 

# collect OS version
echo "OS VERSION" >> $output  
echo "--------------------------------" >> $output
uname -a >> $output | tee >> $output 
echo "" >> $output

# collect shell type
# NEEDS WORK
echo "SHELL TYPE" >> $output
echo "--------------------------------" >> $output
echo $0 >> $output | tee >> $output
echo "" >> $output

# collect Java compiler version
echo "JAVA VERSION" >> $output
echo "--------------------------------" >> $output
java -version 2>> $output | tee >> $output 
echo "" >> $output

# collect Java compiler version
echo "GCC VERSION" >> $output
echo "--------------------------------" >> $output
gcc --version >> $output | tee >> $output 

# collect Ant version
echo "ANT VERSION" >> $output
echo "--------------------------------" >> $output
ant -version 2>&1 1 >> $output | tee >> $output 

# try running UE with test plan
echo "" >> $output
echo "TEST RUN OF TEST EXEC" >> $output
echo "--------------------------------" >> $output
plexiltest -p $PLEXIL_HOME/examples/basic/CruiseControl.plx \
 -s $PLEXIL_HOME/examples/basic/scripts/CruiseControl.psx >> $output | tee >> $output
